package com.syyo.admin.controller;

import com.syyo.admin.domain.req.NodeConfigReq;
import com.syyo.admin.service.FlowService;
import com.syyo.common.anno.SysLog;
import com.syyo.common.domain.ResultVo;
import com.syyo.common.utils.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
* @author wang
* @date 2021-04-09 11:35:04
*/
@Api(tags = "流程管理")
@RestController
@RequestMapping("/flow")
public class FlowController {

    @Autowired
    private FlowService flowService;

     /**
     * 节点属性新增
     * @param
     * @return
     */
    @SysLog("流程新增")
    @ApiOperation("流程新增")
    @PreAuthorize("@syyo.check('system:flow:add')")
    @PostMapping
    public ResultVo add(@RequestBody NodeConfigReq req){
        return ResultUtils.ok(flowService.add(req));
    }


    /**
     * 节点属性详情
     * @param
     * @return
     */
    @ApiOperation("流程查询")
    @GetMapping
    public ResultVo findOne(@RequestParam("tempType") Integer tempType,
                            @RequestParam(value = "version",required = false) Long version){
        return  ResultUtils.ok(flowService.findOne(tempType,version));
    }

    /**
     * 预览
     * @param
     * @return
     */
    @GetMapping("/match/test")
    public ResultVo matchTest(@RequestParam("userId") Integer userId,
                              @RequestParam("tempType") Integer tempType,
                              @RequestParam(value = "version",required = false) Long version){
        return  ResultUtils.ok(flowService.matchTest(userId,tempType,version));
    }

}